//----------------登录检测-------------------------------
var signin = new Vue({
	el: '#signinVue',
	data: {

	},
	methods: {

//------------------------登录验证----------------------------
        signinCheck: function() {
            var signinInput;
            var signinFy;
            signinInput = this.$options.methods.form2JsonSignin(); //表格的信息序列化后转json

             var signinMsg= signinInput; //把数据转成一个对象包着一个对象
            signinFy = JSON.stringify(signinMsg); //把要传的数据转成要求的json格式
            console.log(signinFy);
            // para= decodeURIComponent(para,true);//解决中文乱码的问题

            // console.log(para);
            // para = JSON.stringify(para) ;
            // this.userId = this.inputUserId;
            // this.userName = this.inputUserName;
            // this.userGender = this.inputUserGender;
            // this.userPosition = this.inputUserPosition;
            // this.userPhone = this.inputUserPhone;
            // this.userAddress = this.inputUserAddress;
            // this.userDescribe = this.inputUserDescribe;

            $.ajax({
                type: "post",//数据发送的方式（post 或者 get）
                url: "http://localhost:8080/system/login",//要发送的后台地址
                data: signinFy,
                // "userId":this.userId,
                // "userName":this.userName,
                // "userGender":this.userGender,
                // "userPosition":this.userPosition,//职位
                // "userPhone":this.userPhone,
                // "userAddress":this.userAddress,
                // "userDescribe":this.userDescribe


                //要发送的数据（参数）格式为{'val1':"1","val2":"2"}
                dataType: "json",//后台处理后返回的数据格式
                contentType:"application/json",

                success: function (data) {//ajax请求成功后触发的方法
                    if(data.result=="true"){
                        alert('登录成功');
                        window.location.href="http://localhost:8080/index.html";
                    }


                },
                error: function (msg) {//ajax请求失败后触发的方法


                    console.log(msg);

                }
            });

        },
        //form数据转为json数据
        form2JsonSignin: function() {

            var arr = $("#signIn" ).serializeArray();
            var jsonStr = "";

            jsonStr += '{';
            for (var i = 0; i < arr.length; i++) {
                jsonStr += '"' + arr[i].name + '":"' + arr[i].value + '",'
            }
            jsonStr = jsonStr.substring(0, (jsonStr.length - 1));
            jsonStr += '}';

            var json = JSON.parse(jsonStr);
            return json;

        }


	}
});


//------------------------注册验证----------------------------
//注册检测
var signup = new Vue({
    el: '#signupVue',
    data: {

    },
    methods: {


        signupCheck: function() {
            var signupInput;
            var signupFy;
            signupInput = this.$options.methods.form2JsonSignup(); //表格的信息序列化后转json

            var signupMsg= {user:signupInput}; //把数据转成一个对象包着一个对象
            signupFy = JSON.stringify(signupMsg); //把要传的数据转成要求的json格式
            console.log(signupFy);
            // para= decodeURIComponent(para,true);//解决中文乱码的问题

            // console.log(para);
            // para = JSON.stringify(para) ;
            // this.userId = this.inputUserId;
            // this.userName = this.inputUserName;
            // this.userGender = this.inputUserGender;
            // this.userPosition = this.inputUserPosition;
            // this.userPhone = this.inputUserPhone;
            // this.userAddress = this.inputUserAddress;
            // this.userDescribe = this.inputUserDescribe;

            $.ajax({
                type: "post",//数据发送的方式（post 或者 get）
                url: "http://localhost:8080/system/register",//要发送的后台地址
                data: signupFy,
                // "userId":this.userId,
                // "userName":this.userName,
                // "userGender":this.userGender,
                // "userPosition":this.userPosition,//职位
                // "userPhone":this.userPhone,
                // "userAddress":this.userAddress,
                // "userDescribe":this.userDescribe


                //要发送的数据（参数）格式为{'val1':"1","val2":"2"}
                dataType: "json",//后台处理后返回的数据格式
                contentType:"application/json",

                success: function (data) {//ajax请求成功后触发的方法
                    if(data.result=="true"){
                        alert('注册成功');
                        window.location.href="http://localhost:8080/signin.html";
                    }


                },
                error: function (msg) {//ajax请求失败后触发的方法


                    console.log(msg);

                }
            });

        },
        //form数据转为json数据
        form2JsonSignup: function() {

            var arr = $("#signUp" ).serializeArray();
            var jsonStr = "";

            jsonStr += '{';
            for (var i = 0; i < arr.length; i++) {
                jsonStr += '"' + arr[i].name + '":"' + arr[i].value + '",'
            }
            jsonStr = jsonStr.substring(0, (jsonStr.length - 1));
            jsonStr += '}';

            var json = JSON.parse(jsonStr);
            return json;

        }


    }
});